import { toolchain } from "../../toolchain.js";
import { BaseTask, TaskResult } from "./BastTask.js";

export class SpecifiedSVNTask extends BaseTask<void> {
    async run(): Promise<TaskResult<void>> {
        if (toolchain.params.channelCfg.svn_operations == null) {
            console.log('no svn_operations found, skip specified svn task');
            return { success: true, errorCode: 0 };
        }

        process.chdir(toolchain.params.workSpacePath);

        for (const op of toolchain.params.channelCfg.svn_operations) {
            // const args = op.args.map(v => v == '.' ? toolchain.params.workSpacePath : v);
            console.log(`run svn ${op.command} ${op.args.join(' ')}`);
            await toolchain.svnClient.cmd(op.command, op.args);
        }

        return { success: true, errorCode: 0 };
    }
}
